// VideoMap.h: interface for the CVideoMap class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_VIDEOMAP_H__F7781DB7_C3A5_4582_8775_3BC4A0090128__INCLUDED_)
#define AFX_VIDEOMAP_H__F7781DB7_C3A5_4582_8775_3BC4A0090128__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include"windows.h"
extern "C"
{
	#include <libavformat/avformat.h>
	#include <libswscale/swscale.h>
	#pragma comment(lib,"avformat.lib")
	#pragma comment(lib,"avcodec.lib")	
	#pragma comment(lib,"avutil.lib")
	#pragma comment(lib,"avdevice.lib")
	#pragma comment(lib,"avfilter.lib")
	#pragma comment(lib,"swscale.lib")
}
#include<list>
using namespace std;
struct RawData
{
	unsigned char rawdata[64*1024];
	unsigned int  rawlength;
} ;

typedef list<RawData>		CacheList;
class CVideoMap  
{
public:
	FILE		*m_lpFile;
	HANDLE m_hDecodeThread;
	HANDLE m_hReceiveMap;
	HANDLE m_hFormatMap;
	unsigned char * m_lpData;
	unsigned char * m_lpFormat;
	unsigned char * m_lp;
	int  m_nPos;

	AVCodecContext *m_pCodecCtx;
	AVCodec *m_pCodec;
	AVFrame	*m_pFrame;
	AVFrame *m_pFrameRGB;
	CacheList	m_Framelist;
	volatile bool 	m_bDecode;
	DWORD		m_TickCount;
	DWORD		m_TickStartCount;
	DWORD		m_nDecodeFrame;
	int			m_nFramePerSec;
	CodecID		m_id;


	SwsContext *m_ctx ;

	uint8_t  *m_rawData;
	
	int m_nDecodeLength;
	int m_LastWritePos;
	int m_LastWriteBC;
	int m_LastDataLen;
	bool m_bStartDecode;
	int m_MapLen;
	int m_iImageHeight;     // The image height
    int m_iImageWidth;      // The image width
	int m_nCall;
private:
	PixelFormat m_type;
	bool	m_bUpSideDown;
	bool	m_bYVSide;
public:
	int GetImageWidth() { return m_iImageWidth ;}
    int GetImageHeight() { return m_iImageHeight ;}
	CVideoMap();
	virtual ~CVideoMap();

	bool OpenFormatFileMapping();

	bool OpenDataFileMapping();

	unsigned int ReadDataMapLength();

	unsigned int ReadDataLength();

	bool GetNextFrame();

	bool DeCodeNextFrame(RawData &rd);

	bool GetRawData(BYTE pFrame[]);

	int SetType(int nIndex); 

	void Release();

	void StartDecodeThread();

	static DWORD WINAPI DecodeThread(LPVOID Lparameter);

	void OverDecodeThread();


};

#endif // !defined(AFX_VIDEOMAP_H__F7781DB7_C3A5_4582_8775_3BC4A0090128__INCLUDED_)
